
// Copyright (C) 2012 Luca Piccioni
// 
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Collections.Generic;

namespace Derm.Render
{
	/// <summary>
	/// A state describing the light state.
	/// </summary>
	public class LightingState : ShaderUniformState
	{
		#region Lighting State Information

		/// <summary>
		/// The lights set.
		/// </summary>
		[RenderObjectUniformAttribute("ds_Light")]
		public readonly List<Light> Lights = new List<Light>();

		/// <summary>
		/// The number of defined lights.
		/// </summary>
		[RenderObjectUniformAttribute("ds_LightsCount")]
		public int LightsCount { get { return (Lights.Count); } }

		/// <summary>
		/// Two sided lighting.
		/// </summary>
		[RenderObjectUniformAttribute("ds_LightModelType.TwoSided")]
		public bool TwoSided;

		/// <summary>
		/// 
		/// </summary>
		[RenderObjectUniformAttribute("ds_LightModelType.AmbientLighting")]
		public float AmbientLighting = 1.0f;

		#endregion

		#region Position Dependent Lighting State

		/// <summary>
		/// 
		/// </summary>
		/// <param name="worldPosition"></param>
		/// <returns></returns>
		public LightingState GetLightingState(Vertex3f eyePosition)
		{
			LightingState derivedState = new LightingState();

			// Same model
			derivedState.TwoSided = TwoSided;
			derivedState.AmbientLighting = AmbientLighting;

			// Filter lights

			return (derivedState);
		}

		#endregion

		#region ShaderUniformState Overrides

		/// <summary>
		/// The identifier for the blend state.
		/// </summary>
		public static string StateId = "Derm.Shaders.Light.LightModel";

		/// <summary>
		/// The identifier of this RenderState.
		/// </summary>
		public override string Id { get { return (StateId); } }

		/// <summary>
		/// Flag indicating whether the state is context-bound.
		/// </summary>
		/// <remarks>
		/// It returns always true.
		/// </remarks>
		public override bool IsContextBound
		{
			get
			{
				// In compatibility mode, this state shall set Gl.LIGHTING and Gl.LIGHT{0-8} presets
				return (false);
			}
		}

		#endregion
	}
}
